package cn.edu.hit.education.dialog;

import java.text.DecimalFormat;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import cn.edu.hit.education.pojo.Course;
import educationschedule.Activator;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.PojoProperties;

public class CourseDialog extends TitleAreaDialog {
	private DataBindingContext m_bindingContext;
	IPreferenceStore store = Activator.getDefault().getPreferenceStore();
	private DecimalFormat df2 = new DecimalFormat("0.00");
	private Text text;
	private Text textCourseName;
	private Text textCourseCredict;
	private Text textCourseNumber;
	private Text textCoursePeriod;
	private Text textCourseTheoretical;
	private Text textCourseExperiment;
	private Course course;
	
	public CourseDialog(Shell parentShell) {
		super(parentShell);
		// TODO Auto-generated constructor stub
	}
	
	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		composite.setLayout(new GridLayout(1, false));
		
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayout(new GridLayout(2, false));
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Label label = new Label(composite_1, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("\u8BFE\u7A0B\u540D\u79F0");
		
		textCourseName = new Text(composite_1, SWT.BORDER);
		textCourseName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_1 = new Label(composite_1, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_1.setText("\u8BFE\u7A0B\u5B66\u5206");
		
		textCourseCredict = new Text(composite_1, SWT.BORDER);
		textCourseCredict.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_2 = new Label(composite_1, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setText("\u8BFE\u7A0B\u7F16\u53F7");
		
		textCourseNumber = new Text(composite_1, SWT.BORDER);
		textCourseNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_3 = new Label(composite_1, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_3.setText("\u8BFE\u7A0B\u5B66\u65F6");
		
		textCoursePeriod = new Text(composite_1, SWT.BORDER);
		textCoursePeriod.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_4 = new Label(composite_1, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_4.setText("\u7406\u8BBA\u5B66\u65F6");
		
		textCourseTheoretical = new Text(composite_1, SWT.BORDER);
		textCourseTheoretical.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_5 = new Label(composite_1, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_5.setText("\u5B9E\u9A8C\u5B66\u65F6");
		
		textCourseExperiment = new Text(composite_1, SWT.BORDER);
		textCourseExperiment.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_6 = new Label(composite_1, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_6.setText("\u5B66\u65F6\u5355\u4F4D");
		
		Combo comboCourseUnit = new Combo(composite_1, SWT.NONE);
		comboCourseUnit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_7 = new Label(composite_1, SWT.NONE);
		label_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_7.setText("\u9009\u8BFE\u65B9\u5F0F");
		
		Combo comboCourseProperty = new Combo(composite_1, SWT.NONE);
		comboCourseProperty.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_8 = new Label(composite_1, SWT.NONE);
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_8.setText("\u6388\u8BFE\u65B9\u5F0F");
		
		Combo comboCourseMethod = new Combo(composite_1, SWT.NONE);
		comboCourseMethod.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_9 = new Label(composite_1, SWT.NONE);
		label_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_9.setText("\u6388\u8BFE\u5F62\u5F0F");
		
		Combo comboCourseClassroom = new Combo(composite_1, SWT.NONE);
		comboCourseClassroom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		//new Label(composite, SWT.NONE);
		
		/*Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel.setText("\u8BFE\u7A0B\u540D\u79F0");
		
		text = new Text(composite, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));*/
		m_bindingContext = initDataBindings();
		return composite;
	}
	
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("添加新的课程");
	}

	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTextCourseNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textCourseName);
		IObservableValue nameCourseObserveValue = PojoProperties.value("name").observe(course);
		bindingContext.bindValue(observeTextTextCourseNameObserveWidget, nameCourseObserveValue, null, null);
		//
		return bindingContext;
	}
}
